package io.gitee.hchaojie.day05;

import io.gitee.hchaojie.day03.Boss;
import org.junit.Test;

public class TestObject {
    @Test
    public void test() {
        Boss b = new Boss();

        System.out.println(b);
    }

    @Test
    public void testEquals() {
        String s1 = "abc";
        String s2 = "bcd";

        // 判断两个对象，== ，判断两个引用地址是否相等
        System.out.println(s1 == s2);
        
        String s3 = "abc";      // "abc" 在常量池里面，是一个对象
        System.out.println(s1 == s3);

        String s4 = new String("abc");
        System.out.println(s3 == s4);

        // equals: 判断对象的内容是否相等
        System.out.println(s3.equals(s4));
    }

    // 自定义的对象，如何判断相等性
    @Test
    public void testStudent() {
        Student s = new Student("黄", 18, "1001");
        Student s2 = new Student("黄", 18, "1001");
        Student s3 = new Student("黄", 20, "1001");
        Student s4 = s;

        System.out.println(s.equals(s2));
        System.out.println(s.equals(s3));

        System.out.println(s.equals(s4));

        Student s5 = new Student();
        Student s6 = new Student();

//        Student s7 = null;
//        s7.getAge();        // 报空指针异常

        System.out.println(s5.equals(s6));
    }
    
    @Test
    public void testNull() {
        System.out.println(null instanceof Student);
    }
    
    @Test
    public void testStringHash() {
        String s1 = "abc";
        String s2 = "abcd";

        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());
    }
}
